package observer;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

public class ValoareCurentaHistograma extends Canvas implements Observer, ComponentListener{
	
	public void componentHidden(ComponentEvent e){}
	public void componentMoved(ComponentEvent e){}
	public void componentResized(ComponentEvent e){
		count=getWidth();
		valori=new int [count];
	}
	public void componentShown(ComponentEvent e){
		count=getWidth();
		valori=new int[count];
	}
	private int count =100;
	private int[] valori=new int [count];
	
	public ValoareCurentaHistograma(){
		addComponentListener(this);
	}
	
	//notifica obiectele atunci cand se face o schimbare
	public void upDate(Subject s){
		for(int i=0;i<count-1;i++){
			valori[i]=valori[i+1];
		}
		valori[count-1]=s.getVal();
		repaint();
	}
	
	//update-uie interfata grafica
	public void update(Graphics g){
		super.update(g);
	}
	
	//deseneaza obiectele
	public void paint(Graphics g){
		int w=1;
		for(int i=0;i<count;i++){
			g.fillRect(0+w*i, 0, w, valori[i]);
		}
	}

}
